package com.android.xcalendar.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.android.xcalendar.R;
import com.android.xcalendar.util.XCalendarContentManager;
import com.android.xcalendar.model.Event;

public class DayViewActivity extends ListActivity {
	//TextView dateTextView;
	//LinearLayout eventsLayout;
	XCalendarContentManager contentManager = XCalendarContentManager.getInstance();
	//Button btnAddEvent;

	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
		//setContentView(R.layout.dayview);
//	    setListAdapter(new ListAdapter(this, R.layout.dayview, contentManager.getEventsOfDay()));
//		dateTextView = (TextView)findViewById(R.id.Date);
//		eventsLayout = (LinearLayout)findViewById(R.id.linearLayout_EventsList);
//		
//
//		dateTextView.setText(contentManager.getDayViewDateString());
	    
	    //btnAddEvent = (Button) findViewById(R.id.button_add);
	    //btnAddEvent.setOnClickListener(addEventListener);
	    
	    Log.d("wanted", "i'm here!");
	    SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.dayview, 
	    		new String[]{"content_event_title","content_event_start","content_event_end","content_event_remind","content_event_description"}, 
	    		new int[]{R.id.content_event_title, R.id.content_event_start, R.id.content_event_end, R.id.content_event_remind, R.id.content_event_description});
	    setListAdapter(adapter);
	 
	    
	}
	
	
	
	private List<Map<String, Object>> getData(){
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		
		Map<String, Object> map;
		Log.d("wanted", String.valueOf(contentManager.getEventsOfDay().size()));
		for(int i=0;i<this.contentManager.getEventsOfDay().size();i++){
			map = new HashMap<String, Object>();
			map.put("content_event_title", contentManager.getEventsOfDay().get(i).getTitle());
			map.put("content_event_start", contentManager.getEventsOfDay().get(i).getStartTime());
			map.put("content_event_end", contentManager.getEventsOfDay().get(i).getEndTime());
			map.put("content_event_remind", contentManager.getEventsOfDay().get(i).getRemindTime());
//			map.put("content_event_start", (contentManager.getEventsOfDay().get(i).getStartTime().getHours()+":"+contentManager.getEventsOfDay().get(i).getStartTime().getMinutes()));
//			map.put("content_event_end", (contentManager.getEventsOfDay().get(i).getEndTime().getHours()+":"+contentManager.getEventsOfDay().get(i).getEndTime().getMinutes()));
//			map.put("content_event_remind", (contentManager.getEventsOfDay().get(i).getRemindTime().getHours()+":"+contentManager.getEventsOfDay().get(i).getRemindTime().getMinutes()));
			map.put("content_event_description", contentManager.getEventsOfDay().get(i).getDescription());
			list.add(map);
		}
		
		return list;
	}
	
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id){
		this.contentManager.setSelectedEvent(this.contentManager.getEventsOfDay().get(position));
		Log.d("wanted", Long.toString(this.contentManager.getSelectedEvent().getStartTime().getTime()));
		Intent newIntent = new Intent(getApplicationContext(),EventDetailsActivity.class);	
		startActivity(newIntent);
		
	}

}
